package com.meng.configuration;

import com.meng.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created with logindemo.
 * Author: dreamer-1
 * Email: zhong--lei@outllok.com
 * Date: 2018/5/13
 * Time: 下午2:58
 * Description:
 */
@Configuration
//相当于一个xml文件
public class LoginConfiguration implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册拦截器
        LoginInterceptor loginInterceptor = new LoginInterceptor();

        // 拦截路径
        String[] addPathPatterns = {
                "/book/**",
                "/login",
                "/welcome"
        };

        // 排除路径
        String[] excludePathPatterns = {
                "/login",
                "/book/allBook",
                "/login2"

        };

        registry.addInterceptor(loginInterceptor)
                .addPathPatterns(addPathPatterns)
                .excludePathPatterns(excludePathPatterns);

//        // 排除资源请求
//        registry.excludePathPatterns("/css/login/*.css");
//        registry.excludePathPatterns("/js/login/**/*.js");
//        registry.excludePathPatterns("/image/login/*.png");
    }
}
